package com.wanxi.education.common;



import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * @Author: WangRui
 * @Description:
 * @Date: Created in 2021/9/23 0023
 * @Version: 1.0
 */
@Data
@ApiModel(value = "com.wanxi.education.model.vo.agency.AgencyAddVo",description = "机构添加参数对象")
public class CommonResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 成功标志
     */
    @ApiModelProperty(value = "成功标志")
    private boolean success;

    /**
     * 描述信息
     */
    @ApiModelProperty(value = "描述信息")
    private String message;

    /**
     * 返回代码
     */
    @ApiModelProperty(value = "返回代码")
    private Integer code;

    /**
     * 时间戳
     */
    @ApiModelProperty(value = "时间戳")
    private long timestamp = System.currentTimeMillis();

    /**
     * 结果对象
     */
    @ApiModelProperty(value = "返回结果对象")
    private T data;

    public CommonResult() {
    }

    public CommonResult(boolean a, Integer code, String message, T data) {
        this.success = a;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> CommonResult<T> success(String message){
        return new CommonResult<>(true, ResultCode.SUCCESS.getCode(), message, null);
    }
    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     * @param  message 提示信息
     */
    public static <T> CommonResult<T> success(String message,T data) {
        return new CommonResult<>(true,ResultCode.SUCCESS.getCode(), message, data);
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(true,ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }

    public static <T> CommonResult<T> success(ResultCode resultCode,T data){
        return new CommonResult<>(true,resultCode.getCode(), resultCode.getMessage(), data);
    }

    /**
     * 失败返回结果
     * @param message 提示信息
     */
    public static <T> CommonResult<T> failure(String message) {
        return new CommonResult<>(false,ResultCode.FAILED.getCode(), message, null);
    }
    /**
     * 失败返回结果
     * @param message 提示信息
     */
    public static <T> CommonResult<T> failure(Integer code , String message) {
        return new CommonResult<>(false,code, message, null);
    }
    /**
     * 失败返回结果
     * @param message 提示信息
     */
    public static <T> CommonResult<T> failure(String message, T data) {
        return new CommonResult<>(false,ResultCode.FAILED.getCode(), message, data);
    }
    /**
     * 失败返回结果
     * @param resultCode 提示
     */
    public static <T> CommonResult<T> failure(ResultCode resultCode,T data){
        return new CommonResult<>(false,resultCode.getCode(), resultCode.getMessage(), data);
    }

    /**
     * 参数验证失败返回结果
     */
    public static <T> CommonResult<T> validateFailed() {
        return failure(ResultCode.VALIDATE_FAILED.getMessage());
    }

    /**
     * 参数验证失败返回结果
     * @param message 提示信息
     */
    public static <T> CommonResult<T> validateFailed(String message) {
        return new CommonResult<T>(false,ResultCode.VALIDATE_FAILED.getCode(), message, null);
    }

    /**
     * 未登录返回结果
     */
    public static <T> CommonResult<T> unauthorized(T data) {
        CommonResult<T> result = new CommonResult<>(false,ResultCode.UNAUTHORIZED.getCode(),ResultCode.UNAUTHORIZED.getMessage(),data);
        return result;
    }

    /**
     * 未授权返回结果
     */
    public static <T> CommonResult<T> forbidden(T data) {
        CommonResult<T> result = new CommonResult<>(false,ResultCode.FORBIDDEN.getCode(),ResultCode.FORBIDDEN.getMessage(),data);
        return result;
    }
}

